#!/usr/bin/env python

import twitter
import sys
import time

status_log = open("status_log.txt", "w")

api = twitter.Api()
remaining_hits = api.GetRateLimitStatus()["remaining_hits"]
maximum_frequency = api.MaximumHitFrequency()
remaining_hits -= 1

if (len(sys.argv) != 3):
	print "i'm pretty sure you don't know what you're doing"
	print "usage: ./program username codeword"
	sys.exit()
else:
	user_name = sys.argv[1]
	code_word = sys.argv[2]
	print "you have decided to use %r" % (user_name) + " for a username"
	print "you have elected to use %r" % (code_word) + " for a codeword"


print "hits remaining %r" % (remaining_hits)
print "maximum frequency %r" % (maximum_frequency)
while 1:
	if remaining_hits > 5:
		statuses = api.GetUserTimeline(user_name)
		remaining_hits -= 1
	else:
		print "out of api calls, might as well kill myself"
		sys.exit()
	
	statuses = api.GetUserTimeline(user_name)
	remaining_hits -= 1

	for s in statuses:
		status_log.write(s.text.encode('utf-8'))
		status_log.write("\n")

	#if the most recent status is the code word, then do whatever you are supposed to do.
	if statuses[0].text == code_word:
		print "whatever command needed to be issued has been issued"
		sys.exit()
	time.sleep(maximum_frequency)

	# down here I should write some functions to do if the codeword matches...